import 'package:shared_preferences/shared_preferences.dart';

class LyStorage {
  static Future<bool> setString({
    required String key,
    required String value,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    if(value.isEmpty){
      return remove(key);
    }
    return sharedPreferences.setString(key, value);
  }

  static Future<String> getString({
    required String key,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    String? value = sharedPreferences.getString(key);
    return value ?? '';
  }

  static Future<bool> setBool({
    required String key,
    required bool value,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();

    return sharedPreferences.setBool(key, value);
  }

  static Future<bool> getBool({
    required String key,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    bool? value = sharedPreferences.getBool(key);
    return value ?? false;
  }

  static Future<bool> setInt({
    required String key,
    required int value,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    return sharedPreferences.setInt(key, value);
  }

  static Future<int?> getInt({
    required String key,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    return sharedPreferences.getInt(key);
  }

  static Future<bool> setDouble({
    required String key,
    required double value,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    return sharedPreferences.setDouble(key, value);
  }

  static Future<double?> getDouble({
    required String key,
  }) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    return sharedPreferences.getDouble(key);
  }

  static Future<bool> remove(String key) async{
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    return sharedPreferences.remove(key);
  }
}

extension AppStorage on LyStorage {

  /// 保存UserInfo
  /// 保存Token
  /// 保存当前选择的宝宝Id
  /// 保存当前选择的园所

}
